import { axiosMock, delayFn, randArrItem } from '@/services/axiosMock'
import { DEFAULT_PAGE_SIZE } from '@/utils/pagination'
import type { AllPublishPathODTO, IEventListPublishPathListRes } from '../interface'

axiosMock('default', mock => {
  // 获取所有发布轨迹
  mock.onPost(`/tmsapi/event_template/publishPathList`).reply(
    delayFn<IEventListPublishPathListRes>(600, ({ data }) => {
      const size = +data.size || DEFAULT_PAGE_SIZE
      const page = +data.page || 1
      const total = 250

      const records: AllPublishPathODTO[] = Array(size)
        .fill(null)
        .map((_item, index) => {
          const num = (page - 1) * size + index + 1
          return {
            createAt: randArrItem(['2024-11-16 12:12:12', '2024-11-17 09:30:00'], 0.1) || undefined,
            createBy: randArrItem(['Admin', 'Operator'], 0.1) || undefined,
            customer: randArrItem(['Amazon FBA', 'Walmart', 'Target', 'Best Buy'], 0.1) || undefined,
            edd: randArrItem(['11-20', '11-21', '11-22'], 0.1) || undefined,
            eventTime: randArrItem(['2024-11-15 10:00:00', '2024-11-15 11:00:00']),
            fbaId: randArrItem([`FBA${num}`, `FB${num}A`, `F${num}BA`], 0.1) || undefined,
            location: randArrItem(['Seattle, WA, US', 'Los Angeles, CA, US', 'New York, NY, US'], 0.1) || undefined,
            locationType: randArrItem([1, 2, 3, 4, 5, 6], 0.1) || undefined,
            note: randArrItem(['需跟进', '及时更新', '正常运输中'], 0.2) || undefined,
            publishId: num,
            reasonCode: randArrItem(['RC001', 'RC002', 'RC003'], 0.2) || undefined,
            shipTrackStatus: randArrItem([1, 2, 3], 0.1) || undefined,
            statusCode: randArrItem(['SC001', 'SC002', 'SC003'], 0.2) || undefined,
            templateCn: randArrItem(['货物已发出', '货物运输中', '货物已到达'], 0.1) || undefined,
            templateEn: randArrItem(['Package shipped', 'Package in transit', 'Package delivered'], 0.1) || undefined,
            visibleFlag: randArrItem([0, 1]),
            waybillNo: `LH${String(20241116)}${String(num).padStart(4, '0')}`,
          }
        })

      return {
        success: true,
        data: {
          current: page,
          pages: Math.ceil(total / size),
          records,
          size,
          total,
        },
      }
    }),
  )
})
